﻿
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Theme_Index_SingleTypeNews : System.Web.UI.Page
{
    PowerCreator.LMS.Web.CMS.NewType opNewsType = new PowerCreator.LMS.Web.CMS.NewType();
    PowerCreator.LMS.Web.CMS.New opNews = new PowerCreator.LMS.Web.CMS.New();
    protected PowerCreator.LMS.Web.Config.WebConfig config = new PowerCreator.LMS.Web.Config.WebConfig();
    private int iPageSize = 12;
    private string typeid = "0";
    public string search = "";
    private string type = "";

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.QueryString["type"] != null)
            {
                type = Request.QueryString["type"];
            }
            else if (Request.QueryString["typeid"] != null)
            {
                typeid = Request.QueryString["typeid"];
                PowerCreator.LMS.CMS.Entity.VOTNewType vo = new PowerCreator.LMS.CMS.Entity.VOTNewType();
                vo = opNewsType.Load(int.Parse(typeid));
                type = vo.NewTypeName;
            }

            if (type == "jyzx")
                type = "教育资讯";
            else if (type == "jyzt")
                type = "教育专题";
            else if (type == "szyw")
                type = "时政要闻";
            else if (type == "tzgg")
                type = "通知公告";
            ViewState["type"] = type;
            this.Title = type;
            //lbl_typeName.Text = type;
            search = GetSearch(type);
            BinderPager(search);
            BinderNews(search, 1);
        }
    }

  
    //private void BinderNewNews()
    //{
    //    string search = " NewState = 1";
    //    string orderBy = " NewPublishTime desc ";
    //    DataTable dt = opNews.Query(search, orderBy, PowerCreator.LMS.Web.Config.WebConfig.PageSize, 1);
    //    rpt_NewNews.DataSource = dt;
    //    rpt_NewNews.DataBind();
    //}
    private string GetSearch(string strtype)
    {
        string search = string.Format("FKNewNewTypeID = (select top 1 NewTypeID from TNewType where NewTypeName='{0}' ) and NewState = 1", strtype);
        return search;
    }
    private void BinderNews(string search, int pageIndex)
    {
        string orderby = "NewIsTop desc, NewPublishTime desc ";
        DataTable dt1 = opNews.Query(search, orderby, iPageSize,pageIndex);
        for (int j = 0; j < dt1.Rows.Count; j++)
        {
            if (dt1.Rows[j]["NewUrl"] == null)
                dt1.Rows[j]["NewUrl"] = "OpenNews.aspx?NewsID=" + dt1.Rows[j]["NewID"].ToString();
            else if (dt1.Rows[j]["NewUrl"].ToString().Length == 0)
                dt1.Rows[j]["NewUrl"] = "OpenNews.aspx?NewsID=" + dt1.Rows[j]["NewID"].ToString();
        }
        rpt_News.DataSource = dt1;
        rpt_News.DataBind();
    }

    protected void BinderPager(string search)
    {
        AspNetPager1.RecordCount = opNews.Count(search);
        AspNetPager1.PageSize = iPageSize;
    }
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        this.Title = ViewState["type"].ToString();
        //lbl_typeName.Text = ViewState["type"].ToString();
        search = GetSearch(ViewState["type"].ToString());
        BinderNews(search, AspNetPager1.CurrentPageIndex);
    }
}
